package com.yiip.mr.flowsum;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class FlowSumReducer extends Reducer<Text, FlowBean, Text, FlowBean> {

	long up = 0;
	long down = 0;
	@Override
	protected void reduce(Text arg0, Iterable<FlowBean> arg1, Context arg2)
			throws IOException, InterruptedException {
		//1、循环计算下上行和下行
		for (FlowBean flowBean : arg1) {
			up += flowBean.getUpFlow();
			down += flowBean.getDownFlow();
		}
		//2、封装bean
		FlowBean flowBean = new FlowBean(up,down);

		//3、写出
		arg2.write(arg0,flowBean);
		
		
	}
	
	

}
